<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<head>
    <title>Title</title>
    <%@include file="../../common.jsp"%>
</head>
<body>
<h2>杆塔管理</h2>
<hr>
    <form class="layui-form" action="">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">杆塔编号:</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input id="poleCodes" type="text" name="price_min" autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">状态:</label>
                <div class="layui-input-inline">
                    <select id="isStart">
                        <option value="-1">请选择</option>
                        <option value="1">锁定</option>
                        <option value="0">未锁定</option>
                    </select>
                </div>

                <div class="layui-input-inline" style="width: 100px;">
                    <button type="button" class="layui-btn layui-btn-normal" onclick="searchData();"><i class="layui-icon layui-icon-search"></i> 查询</button>
                </div>
            </div>

        </div>
    </form>
    <table class="layui-table" lay-data="{id:'poleTable',url:'${path}/psPole/list', page:true,toolbar:'#toolbarDemo',defaultToolbar: [],even: true}"
           lay-filter="poleTable">
        <thead>
        <tr>
            <th lay-data="{type:'checkbox'}">复选框</th>
            <th lay-data="{field:'id', width:80}">id</th>
            <th lay-data="{field:'poleCode', width:180}">杆塔编号</th>
            <th lay-data="{templet:'#lineName'}">所属线路</th>
            <th lay-data="{field:'creationTime'}">创建时间</th>
            <th lay-data="{field:'createdBy'}">创建人</th>
            <th lay-data="{field:'lastUpdateTime'}">最后更新时间</th>
            <th lay-data="{field:'isStart',templet:'#lockedTem'}">状态</th>
            <th lay-data="{toolbar:'#barDemo'}">操作</th>
        </tr>
        </thead>
    </table>
    <script>

       function searchData(){
            layui.table.reload("poleTable",{
                page:{
                    curr : 1
                },
                where:{
                    "poleCode":$("#poleCodes").val(),
                    "isStart" : $("#isStart").val()
                }
            });
        }


        layui.use(["table"],function () {
            var table = layui.table;

            table.on('toolbar(poleTable)',function (obj) {
                var e = obj.event;
                switch (e) {
                    case "add":
                        $.get('${path}/psPole/form',function (str) {
                            layer.open({
                                type:1,
                                title:'添加用户',
                                area:'700px',
                                content: str,
                                btn: ['确定','取消'],
                                yes : function (index) {
                                    var params = $("#poleForm").serialize();
                                    $.post('${path}/psPole/add',params,function () {
                                        layer.close(index);
                                        layer.msg('添加成功!');
                                        table.reload('poleTable');
                                    });
                                }
                            });
                        });
                        break;
                    case "delete":
                        var rows = table.checkStatus('poleTable');
                        var data = rows.data;
                        if(data.length == 0){
                            layer.msg("请选择要删除的数据",function (){});
                            return;
                        }
                        layer.confirm('确定删除吗？',{icon:5,title:'友情提示'},function (index) {
                           var params = "";
                           for (let pole of data){
                               params+= "ids="+pole.id+"&";
                           }
                            $.post('${path}/psPole/delete',params,function () {
                                layer.close(index);
                                layer.msg('删除成功!');
                                table.reload('poleTable');
                            })
                        });
                        break;

                }
            });

            //监听 行
            table.on("tool(poleTable)",function (obj) {
                var data = obj.data;
                if (obj.event == 'edit'){
                    $.get("${path}/psPole/form",function (str) {
                        layer.open({
                            type:1,
                            title:'修改用户',
                            content:str,
                            area:'700px',
                            skin:'layui-layer-molv',
                            btn:['确定','取消'],
                            success:function(){
                                $.get('${path}/psPole/view',{id:data.id},function () {
                                    //显示数据
                                    layui.form.val('poleForm',data);
                                });
                            },
                            yes : function (index) {
                                var params = $("#poleForm").serialize();
                                $.get("${path}/psPole/update",params,function (data) {
                                        layer.close(index);
                                        layer.msg('修改成功!');
                                        table.reload("poleTable");
                                });
                            }
                         });
                    });
                }else if(obj.event == 'del'){
                    layer.open({
                        time:0,
                        title:'友情提示',
                        content:'确定要删除吗？',
                        btn:['确定','取消'],
                        yes : function () {
                            $.post("${path}/psPole/delete",{"ids":data.id},function () {
                                layer.msg('删除成功！！！');
                                table.reload('poleTable');
                            });
                        }
                    })
                }
            })
        });
    </script>
    <script type="text/html" id="lockedTem">
        <input type="checkbox" title="启用" {{d.isStart == 1 ? 'checked' : ''}}>
    </script>
    <script type="text/html" id="barDemo">
        <a href="javascript:void(0)" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></a>
        <a href="javascript:void(0)" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
    </script>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加</button>
            <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>批量删除</button>
        </div>
    </script>

    <script id="lineName" type="text/html">
        {{d.psLineInfo == null ? '暂无线路' : d.psLineInfo.lineName}}
    </script>

</body>
</html>
